package com.excel.validators.core.decorative;

import com.excel.validators.core.decorative.inner.IDynamicClass;
import com.excel.validators.core.extension.ModelAnalysis;
import com.excel.validators.core.extension.dyna.DynamicAnalysis;
import com.excel.validators.excel.entrance.ThreadLocalSheet;

public abstract class DynamicModel extends ThreadLocalSheet implements IDynamicClass {

	/**
	 * 动态引入的模型
	 */
	private DynamicAnalysis dynamicClass;
	
	@Override
	public <T> void analysisElement(Class<T> basicClass) {
			setNamespace(basicClass.getSimpleName());
			ModelAnalysis analysis = get();
			if (analysis == null) {
					if (dynamicClass == null) {
							dynamicClass = new DynamicAnalysis();
					}
					dynamicClass.analysisElement(basicClass);
					analysis = dynamicClass.createAnalysis(getNamespace());
					if (analysis != null) {
							set(analysis);
					}
					dynamicClass = null;
			}
	}
	
	/*
	 * 获取检查器
	 */
	protected Validator getValidator() {
			ModelAnalysis analysis = get();
			if (analysis != null) {
					return analysis.getValidator();
			}
			return null;
	}
	
}
